### Setup R ###
###############

### Clear terminal
cat("\014")

### Clear space
rm(list = ls())

### Load packages
library(rio)
library(zoo)
library(gtrendsR)

### Import Data ###
###################

### Set WD
setwd("")

#### UK

#### Liberal Party
lib.uk <- import("lib.csv")
head(lib.uk)
colnames(lib.uk) <- c("month", "manifesto", "party")
lib.uk <- transform(lib.uk, month = as.yearmon(month))
lib.uk$manifesto[lib.uk$manifesto == "<1"] <- "0.5"
lib.uk$manifesto <- as.numeric(lib.uk$manifesto)

plot(lib.uk$month, lib.uk$party, ylab="Google Search Popularity", xlab="Time", type='l', lty=5, col="#cccccc", lwd="3", bty='n', ylim=c(0, 100),
     main="Liberal Party and Liberal Democrats", font.main=1)
lines(lib.uk$month, lib.uk$manifesto, type='l', col="#90b3d6", lwd="3")

#### Labour Party
lab.uk <- import("lab.csv")
head(lab.uk)
colnames(lab.uk) <- c("month", "manifesto", "party")
lab.uk <- transform(lab.uk, month = as.yearmon(month))
lab.uk$manifesto[lab.uk$manifesto == "<1"] <- "0.5"
lab.uk$manifesto <- as.numeric(lab.uk$manifesto)

plot(lab.uk$month, lab.uk$party, ylab="Google Search Popularity", xlab="Time", type='l', lty=5, col="#cccccc", lwd="3", bty='n', ylim=c(0, 100),
     main="Labour Party", font.main=1)
lines(lab.uk$month, lab.uk$manifesto, type='l', col="#90b3d6", lwd="3")

#### Conservative Party
con.uk <- import("cons.csv")
head(con.uk)
colnames(con.uk) <- c("month", "manifesto", "party")
con.uk <- transform(con.uk, month = as.yearmon(month))
con.uk$manifesto[con.uk$manifesto == "<1"] <- "0.5"
con.uk$manifesto <- as.numeric(con.uk$manifesto)

plot(con.uk$month, con.uk$party, ylab="Google Search Popularity", xlab="Time", type='l', lty=5, col="#cccccc", lwd="3", bty='n', ylim=c(0, 100),
     main="Conservative Party", font.main=1)
lines(con.uk$month, con.uk$manifesto, type='l', col="#90b3d6", lwd="3")

par(mfrow=c(3, 1))

plot(con.uk$month, con.uk$party, ylab="Google Search Popularity", xlab="Time", type='l', lty=5, col="#cccccc", lwd="3", bty='n', ylim=c(0, 100),
     main="Conservative Party", font.main=1)
lines(con.uk$month, con.uk$manifesto, type='l', col="#90b3d6", lwd="3")

plot(lab.uk$month, lab.uk$party, ylab="Google Search Popularity", xlab="Time", type='l', lty=5, col="#cccccc", lwd="3", bty='n', ylim=c(0, 100),
     main="Labour Party", font.main=1)
lines(lab.uk$month, lab.uk$manifesto, type='l', col="#90b3d6", lwd="3")

plot(lib.uk$month, lib.uk$party, ylab="Google Search Popularity", xlab="Time", type='l', lty=5, col="#cccccc", lwd="3", bty='n', ylim=c(0, 100),
     main="Liberal Party and Liberal Democrats", font.main=1)
lines(lib.uk$month, lib.uk$manifesto, type='l', col="#90b3d6", lwd="3")